module.exports = (app) => {
  const { INTEGER, DATE } = app.Sequelize;

  const DirectoryArticle = app.model.define(
    "directory-article",
    {
      directoryId: {
        type: INTEGER,
        allowNull: false,
      },
      articleId: {
        type: INTEGER,
        allowNull: false,
      },
      isTop: {
        type: INTEGER,
        defaultValue: 0,
      },
    },
    {
      timestamps: true,
      underscored: false,
    }
  );

  DirectoryArticle.associate = function () {
    DirectoryArticle.Article = DirectoryArticle.belongsTo(app.model.Article, {
      foreignKey: "articleId",
      as: "article", // 别名，用于查询时引用
    });
  };

  return DirectoryArticle;
};
